package com.microcore.dao.mapper;

import com.microcore.entity.InvokeTrigger;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface InvokeTriggerMapper {
    @Delete({
        "delete from tb_ssgp_invoke_trigger",
        "where trigger_id = #{invokeTriggerId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String invokeTriggerId);

    @Insert({
        "insert into tb_ssgp_invoke_trigger (trigger_id, foreign_key_id, ",
        "start_datetime, end_datetime, ",
        "count, trigger_interval, ",
        "cron_expression, trigger_name, ",
        "start_time, end_time, params)",
        "values (#{invokeTriggerId,jdbcType=VARCHAR}, #{fkId,jdbcType=VARCHAR}, ",
        "#{startDatetime,jdbcType=TIMESTAMP}, #{endDatetime,jdbcType=TIMESTAMP}, ",
        "#{count,jdbcType=INTEGER}, #{interval,jdbcType=INTEGER}, ",
        "#{cronExpression,jdbcType=VARCHAR}, #{triggerName,jdbcType=VARCHAR}, ",
        "#{startTime,jdbcType=VARCHAR}, #{endTime,jdbcType=VARCHAR}, #{params,jdbcType=VARCHAR})"
    })
    int insert(InvokeTrigger record);

    @InsertProvider(type=InvokeTriggerSqlProvider.class, method="insertSelective")
    int insertSelective(InvokeTrigger record);

    @Select({
        "select",
        "trigger_id, foreign_key_id, start_datetime, end_datetime, count, trigger_interval, ",
        "cron_expression, trigger_name, start_time, end_time, params",
        "from tb_ssgp_invoke_trigger",
        "where trigger_id = #{invokeTriggerId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="trigger_id", property="invokeTriggerId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="foreign_key_id", property="fkId", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_datetime", property="startDatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_datetime", property="endDatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="trigger_interval", property="interval", jdbcType=JdbcType.INTEGER),
        @Result(column="cron_expression", property="cronExpression", jdbcType=JdbcType.VARCHAR),
        @Result(column="trigger_name", property="triggerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_time", property="startTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="end_time", property="endTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="params", property="params", jdbcType=JdbcType.VARCHAR)
    })
    InvokeTrigger selectByPrimaryKey(String invokeTriggerId);

    @UpdateProvider(type=InvokeTriggerSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(InvokeTrigger record);

    @Update({
        "update tb_ssgp_invoke_trigger",
        "set foreign_key_id = #{fkId,jdbcType=VARCHAR},",
          "start_datetime = #{startDatetime,jdbcType=TIMESTAMP},",
          "end_datetime = #{endDatetime,jdbcType=TIMESTAMP},",
          "count = #{count,jdbcType=INTEGER},",
          "trigger_interval = #{interval,jdbcType=INTEGER},",
          "cron_expression = #{cronExpression,jdbcType=VARCHAR},",
          "trigger_name = #{triggerName,jdbcType=VARCHAR},",
          "start_time = #{startTime,jdbcType=VARCHAR},",
          "end_time = #{endTime,jdbcType=VARCHAR}",
          "params = #{params,jdbcType=VARCHAR}",
        "where trigger_id = #{invokeTriggerId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(InvokeTrigger record);

    @Select({
    	"select ",
    	"trigger_id, foreign_key_id, start_datetime, end_datetime, count, trigger_interval, ",
        "cron_expression, trigger_name, start_time, end_time, params",
        "from tb_ssgp_invoke_trigger",
        "where foreign_key_id = #{fkId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="trigger_id", property="invokeTriggerId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="foreign_key_id", property="fkId", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_datetime", property="startDatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_datetime", property="endDatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="trigger_interval", property="interval", jdbcType=JdbcType.INTEGER),
        @Result(column="cron_expression", property="cronExpression", jdbcType=JdbcType.VARCHAR),
        @Result(column="trigger_name", property="triggerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_time", property="startTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="end_time", property="endTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="params", property="params", jdbcType=JdbcType.VARCHAR)
    })
    List<InvokeTrigger> getTriggersByInvokeId(@Param("fkId") String fkId);
    
    @Delete({
    	"delete from tb_ssgp_invoke_trigger",
        "where foreign_key_id = #{fkId,jdbcType=VARCHAR}"
    })
    void deleteByFkId(String fkId);
}
